package com.qf.homework.util;

import cn.hutool.core.text.csv.CsvUtil;
import cn.hutool.core.text.csv.CsvWriter;
import cn.hutool.core.util.CharsetUtil;
import com.qf.homework.dao.BookDao;
import com.qf.homework.entity.Book;

import java.util.Iterator;
import java.util.List;

public class GetCSVFile {

    public static void getCSVf(String filePath){
        CsvWriter writer = CsvUtil.getWriter(filePath, CharsetUtil.CHARSET_UTF_8);
        BookDao mapper = Batis01Util.getMapper(BookDao.class);
        for (int i = 0; i < 250; i++) {
            List<Book> books = mapper.getBooks(i * 2000);
            Iterator<Book> iterator = books.iterator();
            while (iterator.hasNext()) {
                String s = iterator.next().toString();
                String[] split = s.split(",");
                writer.write(split);
            }
        }
        writer.close();
    }
}
